{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.337669Z",
     "start_time": "2025-09-16T06:58:15.819803Z"
    }
   },
   "source": [
    "import spacy\n",
    "nlp = spacy.load('en_core_web_lg')"
   ],
   "outputs": [],
   "execution_count": 72
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "文本处理",
   "id": "f87725e853950998"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.358609Z",
     "start_time": "2025-09-16T06:58:17.338674Z"
    }
   },
   "cell_type": "code",
   "source": "doc = nlp('Weather is good, very windy and sunny. we have no classes in the afternoon.')",
   "id": "451b253b3cd7c38a",
   "outputs": [],
   "execution_count": 73
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.364475Z",
     "start_time": "2025-09-16T06:58:17.359787Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#分词\n",
    "for token in doc:\n",
    "    print(token)"
   ],
   "id": "d2a43e072b54fdc1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weather\n",
      "is\n",
      "good\n",
      ",\n",
      "very\n",
      "windy\n",
      "and\n",
      "sunny\n",
      ".\n",
      "we\n",
      "have\n",
      "no\n",
      "classes\n",
      "in\n",
      "the\n",
      "afternoon\n",
      ".\n"
     ]
    }
   ],
   "execution_count": 74
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.374366Z",
     "start_time": "2025-09-16T06:58:17.367344Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#分句\n",
    "for sent in doc.sents:\n",
    "    print(sent)"
   ],
   "id": "d551f1a4754b856b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weather is good, very windy and sunny.\n",
      "we have no classes in the afternoon.\n"
     ]
    }
   ],
   "execution_count": 75
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.379196Z",
     "start_time": "2025-09-16T06:58:17.374366Z"
    }
   },
   "cell_type": "code",
   "source": [
    "for token in doc:\n",
    "    print('{}-{}'.format(token,token.pos_))"
   ],
   "id": "6c591fdfac4e3ab7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weather-NOUN\n",
      "is-AUX\n",
      "good-ADJ\n",
      ",-PUNCT\n",
      "very-ADV\n",
      "windy-ADJ\n",
      "and-CCONJ\n",
      "sunny-ADJ\n",
      ".-PUNCT\n",
      "we-PRON\n",
      "have-VERB\n",
      "no-DET\n",
      "classes-NOUN\n",
      "in-ADP\n",
      "the-DET\n",
      "afternoon-NOUN\n",
      ".-PUNCT\n"
     ]
    }
   ],
   "execution_count": 76
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "词性：https://zhuanlan.zhihu.com/p/427520069",
   "id": "88fee29b9f8225a6"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.395233Z",
     "start_time": "2025-09-16T06:58:17.380482Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#命名体识别\n",
    "doc_2 = nlp('I went to Paris where I met my old friend Jack from uni.')\n",
    "for ent in doc_2.ents:\n",
    "    print('{}-{}'.format(ent,ent.label_))"
   ],
   "id": "9fc7b0c61e6d9064",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paris-GPE\n",
      "Jack-PERSON\n"
     ]
    }
   ],
   "execution_count": 77
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.409652Z",
     "start_time": "2025-09-16T06:58:17.395233Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from spacy import displacy\n",
    "doc = nlp('I went to Paris where I met my old friend Jack from uni.')\n",
    "displacy.render(doc, style='ent',jupyter=True)"
   ],
   "id": "5c96a8bb32eee7ef",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ],
      "text/html": [
       "<span class=\"tex2jax_ignore\"><div class=\"entities\" style=\"line-height: 2.5; direction: ltr\">I went to \n",
       "<mark class=\"entity\" style=\"background: #feca74; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;\">\n",
       "    Paris\n",
       "    <span style=\"font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem\">GPE</span>\n",
       "</mark>\n",
       " where I met my old friend \n",
       "<mark class=\"entity\" style=\"background: #aa9cfc; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;\">\n",
       "    Jack\n",
       "    <span style=\"font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem\">PERSON</span>\n",
       "</mark>\n",
       " from uni.</div></span>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 78
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:17.414247Z",
     "start_time": "2025-09-16T06:58:17.410664Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 找到书中所有人物的名字\n",
    "def read_file(file_name):\n",
    "    with open(file_name,'r') as file:\n",
    "        return file.read()"
   ],
   "id": "ef21d1cd715cb89f",
   "outputs": [],
   "execution_count": 79
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:48.640577Z",
     "start_time": "2025-09-16T06:58:17.414247Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#加载文本数据\n",
    "text = read_file('./data/pride_and_prejudice.txt')\n",
    "processed_text = nlp(text)\n",
    "sentences = [s for s in processed_text.sents]\n",
    "print(len(sentences))"
   ],
   "id": "52c18ddd7b24a49d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5771\n"
     ]
    }
   ],
   "execution_count": 80
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:48.647913Z",
     "start_time": "2025-09-16T06:58:48.643148Z"
    }
   },
   "cell_type": "code",
   "source": "sentences[:5]",
   "id": "40475e6400a5db62",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[The Project Gutenberg EBook of Pride and Prejudice, by Jane Austen\n",
       " \n",
       " This eBook is for the use of anyone anywhere at no cost and with\n",
       " almost no restrictions whatsoever.  ,\n",
       " You may copy it, give it away or\n",
       " re-use it under the terms of the Project Gutenberg License included\n",
       " with this eBook or online at www.gutenberg.org\n",
       " \n",
       " \n",
       " Title:,\n",
       " Pride and Prejudice\n",
       " \n",
       " Author: Jane Austen\n",
       " \n",
       " Posting Date: August 26, 2008,\n",
       " [EBook #1342]\n",
       " Release Date: June, 1998\n",
       " Last updated:,\n",
       " February 15, 2015]\n",
       " \n",
       " Language: English\n",
       " \n",
       " \n",
       " *** START OF THIS PROJECT GUTENBERG EBOOK PRIDE AND PREJUDICE ***\n",
       " \n",
       " \n",
       " \n",
       " \n",
       " Produced by Anonymous Volunteers\n",
       " \n",
       " \n",
       " \n",
       " \n",
       " \n",
       " PRIDE AND PREJUDICE\n",
       " \n",
       " By Jane Austen\n",
       " \n",
       " \n",
       " \n",
       " Chapter 1\n",
       " \n",
       " ]"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 81
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:48.666043Z",
     "start_time": "2025-09-16T06:58:48.647913Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from collections import Counter,defaultdict\n",
    "def find_person(doc):\n",
    "    c = Counter()\n",
    "    for ent in processed_text.ents:\n",
    "        if ent.label_ == 'PERSON':\n",
    "            c[ent.lemma_] += 1\n",
    "    return c.most_common(10)\n",
    "print(find_person(processed_text))"
   ],
   "id": "2351b7f2a00aaa1f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Elizabeth', 625), ('Darcy', 412), ('Bennet', 299), ('Bingley', 294), ('Jane', 287), ('Wickham', 180), ('Collins', 179), ('Lydia', 163), ('Lizzy', 94), ('Gardiner', 94)]\n"
     ]
    }
   ],
   "execution_count": 82
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:48.670211Z",
     "start_time": "2025-09-16T06:58:48.667141Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#恐怖袭击分析\n",
    "def read_file_to_list(file_name):\n",
    "    with open(file_name,'r') as file:\n",
    "        return file.readlines()"
   ],
   "id": "1cdd49437944e42a",
   "outputs": [],
   "execution_count": 83
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T06:58:48.691139Z",
     "start_time": "2025-09-16T06:58:48.670211Z"
    }
   },
   "cell_type": "code",
   "source": [
    "terrorism_articles = read_file_to_list('./data/rand-terrorism-dataset.txt')\n",
    "terrorism_articles[:5]"
   ],
   "id": "d58ab455ad082587",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['CHILE.  An explosion from a single stick of dynamite went off on the patio of the Santiago Binational Center, causing $21,000 in damages.\\n',\n",
       " 'ISRAEL.  Palestinian terrorists fired five mortar shells into the collective settlement at Masada, causing slight damage but no injuries.\\n',\n",
       " 'GUATEMALA.  A bomb was thrown over the wall surrounding the U.S. Marines guards house in Guatemala City, causing damage but no injuries.\\n',\n",
       " 'FRANCE.  Five French students bombed the Paris offices of   Chase Manhattan Bank before dawn.  Trans-World Airways and the Bank of America were also bombed.   They claimed to be protesting the U.S. involvement in the Vietnam war.\\n',\n",
       " 'UNITED STATES - Unidentified anti-Castro Cubans attempted to bomb the Miami branch of the Spanish National Tourist Office.\\n']"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 84
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T07:01:52.488265Z",
     "start_time": "2025-09-16T06:58:48.692145Z"
    }
   },
   "cell_type": "code",
   "source": "terrorism_articles_nlp = [nlp(art) for art in terrorism_articles]",
   "id": "d1ecc2b3bf163b5b",
   "outputs": [],
   "execution_count": 85
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T07:01:52.493669Z",
     "start_time": "2025-09-16T07:01:52.488265Z"
    }
   },
   "cell_type": "code",
   "source": [
    "common_terrorism_groups = [\n",
    "    'taliban',\n",
    "    'al - qaeda',\n",
    "    'hamas',\n",
    "    'fatah',\n",
    "    'plo',\n",
    "    'bilad al - rafidayn'\n",
    "]\n",
    "common_locations = [\n",
    "    'iraq',\n",
    "    'baghdad',\n",
    "    'kirkuk',\n",
    "    'mosul',\n",
    "    'afghanistam',\n",
    "    'kabul',\n",
    "    'basra',\n",
    "    'palestine',\n",
    "    'gaza',\n",
    "    'israel',\n",
    "    'istanbul',\n",
    "    'beirut',\n",
    "    'pakistan'\n",
    "]"
   ],
   "id": "93e5de44b02504e5",
   "outputs": [],
   "execution_count": 86
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T07:02:54.464251Z",
     "start_time": "2025-09-16T07:02:54.284316Z"
    }
   },
   "cell_type": "code",
   "source": [
    "location_entity_dict = defaultdict(Counter)\n",
    "for article in terrorism_articles_nlp:\n",
    "    article_terrorist_groups = [ent.lemma_ for ent in article.ents if ent.label_ == 'PERSON' or ent.label_ =='ORG' ]#人或组织\n",
    "    article_locations = [ent.lemma_ for ent in article.ents if ent.label_ =='GPE']#地点\n",
    "    terrorism_common = [ent for ent in article_terrorist_groups if ent in common_terrorism_groups]\n",
    "    location_common = [ent for ent in article_locations if ent in common_locations]\n",
    "    \n",
    "    for found_entity in terrorism_common:\n",
    "        for found_location in location_common:\n",
    "            location_entity_dict[found_entity][found_location] += 1"
   ],
   "id": "eaaa0e9fc798599e",
   "outputs": [],
   "execution_count": 90
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T07:07:18.452187Z",
     "start_time": "2025-09-16T07:07:18.447027Z"
    }
   },
   "cell_type": "code",
   "source": [
    " import pandas as pd\n",
    "location_entity_df = pd.DataFrame.from_dict(dict(location_entity_dict),dtype=int)\n",
    "location_entity_df = location_entity_df.fillna(value=0).astype(int)\n",
    "location_entity_df"
   ],
   "id": "26915c9e922ba14b",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 93
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-16T07:07:13.433532Z",
     "start_time": "2025-09-16T07:07:13.291894Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "plt.figure(figsize=(12,10))\n",
    "hmap = sns.heatmap(location_entity_df,annot=True,fmt='d',cmap='YlGnBu',cbar=False)\n",
    "\n",
    "#添加信息\n",
    "plt.title(\"Gloabl Incident by Terrorism Group\")\n",
    "plt.xticks(rotation=30)\n",
    "plt.show()"
   ],
   "id": "e00a698be7d464aa",
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "zero-size array to reduction operation fmin which has no identity",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[92], line 4\u001B[0m\n\u001B[0;32m      2\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mseaborn\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m \u001B[38;5;21;01msns\u001B[39;00m\n\u001B[0;32m      3\u001B[0m plt\u001B[38;5;241m.\u001B[39mfigure(figsize\u001B[38;5;241m=\u001B[39m(\u001B[38;5;241m12\u001B[39m,\u001B[38;5;241m10\u001B[39m))\n\u001B[1;32m----> 4\u001B[0m hmap \u001B[38;5;241m=\u001B[39m \u001B[43msns\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mheatmap\u001B[49m\u001B[43m(\u001B[49m\u001B[43mlocation_entity_df\u001B[49m\u001B[43m,\u001B[49m\u001B[43mannot\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m,\u001B[49m\u001B[43mfmt\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43md\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43mcmap\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mYlGnBu\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43mcbar\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mFalse\u001B[39;49;00m\u001B[43m)\u001B[49m\n\u001B[0;32m      6\u001B[0m \u001B[38;5;66;03m#添加信息\u001B[39;00m\n\u001B[0;32m      7\u001B[0m plt\u001B[38;5;241m.\u001B[39mtitle(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mGloabl Incident by Terrorism Group\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "File \u001B[1;32mD:\\software\\Anaconda3\\envs\\d2l-zh\\Lib\\site-packages\\seaborn\\matrix.py:446\u001B[0m, in \u001B[0;36mheatmap\u001B[1;34m(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, xticklabels, yticklabels, mask, ax, **kwargs)\u001B[0m\n\u001B[0;32m    365\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Plot rectangular data as a color-encoded matrix.\u001B[39;00m\n\u001B[0;32m    366\u001B[0m \n\u001B[0;32m    367\u001B[0m \u001B[38;5;124;03mThis is an Axes-level function and will draw the heatmap into the\u001B[39;00m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    443\u001B[0m \n\u001B[0;32m    444\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m    445\u001B[0m \u001B[38;5;66;03m# Initialize the plotter object\u001B[39;00m\n\u001B[1;32m--> 446\u001B[0m plotter \u001B[38;5;241m=\u001B[39m \u001B[43m_HeatMapper\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdata\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mvmin\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mvmax\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcmap\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcenter\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrobust\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mannot\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mfmt\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    447\u001B[0m \u001B[43m                      \u001B[49m\u001B[43mannot_kws\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcbar\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcbar_kws\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mxticklabels\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    448\u001B[0m \u001B[43m                      \u001B[49m\u001B[43myticklabels\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmask\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    450\u001B[0m \u001B[38;5;66;03m# Add the pcolormesh kwargs here\u001B[39;00m\n\u001B[0;32m    451\u001B[0m kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mlinewidths\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m linewidths\n",
      "File \u001B[1;32mD:\\software\\Anaconda3\\envs\\d2l-zh\\Lib\\site-packages\\seaborn\\matrix.py:163\u001B[0m, in \u001B[0;36m_HeatMapper.__init__\u001B[1;34m(self, data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask)\u001B[0m\n\u001B[0;32m    160\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mylabel \u001B[38;5;241m=\u001B[39m ylabel \u001B[38;5;28;01mif\u001B[39;00m ylabel \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    162\u001B[0m \u001B[38;5;66;03m# Determine good default values for the colormapping\u001B[39;00m\n\u001B[1;32m--> 163\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_determine_cmap_params\u001B[49m\u001B[43m(\u001B[49m\u001B[43mplot_data\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mvmin\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mvmax\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    164\u001B[0m \u001B[43m                            \u001B[49m\u001B[43mcmap\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcenter\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrobust\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    166\u001B[0m \u001B[38;5;66;03m# Sort out the annotations\u001B[39;00m\n\u001B[0;32m    167\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m annot \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mor\u001B[39;00m annot \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mFalse\u001B[39;00m:\n",
      "File \u001B[1;32mD:\\software\\Anaconda3\\envs\\d2l-zh\\Lib\\site-packages\\seaborn\\matrix.py:202\u001B[0m, in \u001B[0;36m_HeatMapper._determine_cmap_params\u001B[1;34m(self, plot_data, vmin, vmax, cmap, center, robust)\u001B[0m\n\u001B[0;32m    200\u001B[0m         vmin \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mnanpercentile(calc_data, \u001B[38;5;241m2\u001B[39m)\n\u001B[0;32m    201\u001B[0m     \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 202\u001B[0m         vmin \u001B[38;5;241m=\u001B[39m \u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mnanmin\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcalc_data\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    203\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m vmax \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    204\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m robust:\n",
      "File \u001B[1;32mD:\\software\\Anaconda3\\envs\\d2l-zh\\Lib\\site-packages\\numpy\\lib\\_nanfunctions_impl.py:356\u001B[0m, in \u001B[0;36mnanmin\u001B[1;34m(a, axis, out, keepdims, initial, where)\u001B[0m\n\u001B[0;32m    351\u001B[0m     kwargs[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mwhere\u001B[39m\u001B[38;5;124m'\u001B[39m] \u001B[38;5;241m=\u001B[39m where\n\u001B[0;32m    353\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m (\u001B[38;5;28mtype\u001B[39m(a) \u001B[38;5;129;01mis\u001B[39;00m np\u001B[38;5;241m.\u001B[39mndarray \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;28mtype\u001B[39m(a) \u001B[38;5;129;01mis\u001B[39;00m np\u001B[38;5;241m.\u001B[39mmemmap) \u001B[38;5;129;01mand\u001B[39;00m a\u001B[38;5;241m.\u001B[39mdtype \u001B[38;5;241m!=\u001B[39m np\u001B[38;5;241m.\u001B[39mobject_:\n\u001B[0;32m    354\u001B[0m     \u001B[38;5;66;03m# Fast, but not safe for subclasses of ndarray, or object arrays,\u001B[39;00m\n\u001B[0;32m    355\u001B[0m     \u001B[38;5;66;03m# which do not implement isnan (gh-9009), or fmin correctly (gh-8975)\u001B[39;00m\n\u001B[1;32m--> 356\u001B[0m     res \u001B[38;5;241m=\u001B[39m \u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfmin\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mreduce\u001B[49m\u001B[43m(\u001B[49m\u001B[43ma\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43maxis\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43maxis\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mout\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mout\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    357\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m np\u001B[38;5;241m.\u001B[39misnan(res)\u001B[38;5;241m.\u001B[39many():\n\u001B[0;32m    358\u001B[0m         warnings\u001B[38;5;241m.\u001B[39mwarn(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAll-NaN slice encountered\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;167;01mRuntimeWarning\u001B[39;00m,\n\u001B[0;32m    359\u001B[0m                       stacklevel\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m2\u001B[39m)\n",
      "\u001B[1;31mValueError\u001B[0m: zero-size array to reduction operation fmin which has no identity"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 1200x1000 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 92
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "",
   "id": "f4abe3fb46933087",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
